package com.ruoyi.auth.controller;

import com.ruoyi.auth.service.SmsLoginService;
import com.ruoyi.common.core.domain.*;
import com.ruoyi.common.core.service.IMerchantImgsService;
import com.ruoyi.common.core.service.IMerchantService;
import com.ruoyi.common.core.service.IMerchantVerificationService;
import com.ruoyi.common.core.service.IUserService;
import com.ruoyi.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/auth/sms")
public class AuthSmsController {
    @Autowired
    private SmsLoginService smsLoginService;
    private static final String SMS_CODE_KEY = "sms:code:";
    @PostMapping("/send")
    /*
    * 商家注册、商家端登录、用户端登录统一验证码发送接口
    * */
    public R sendCode(@RequestBody Map<String, Object> params)
    {
        String phone = (String) params.get("phone");
        String type = (String) params.get("type");
        return smsLoginService.sendRegisterAndLoginCode(phone, type);
    }
    /*
    * 商家端登录、用户端登录接口
    * */
    @PostMapping("/login")
    public R login(@RequestBody Map<String, Object> params) {
            String phone = (String) params.get("phone");
            String code = (String) params.get("code");
            return smsLoginService.login(phone, code);
        }
    /*
    * 商家端注册接口
    * */
    @PostMapping("/register")
    public R register(@RequestBody Map<String, Object> params){
        return smsLoginService.register(params);
    }

}
